package com.example.vv.model.register;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.example.vv.R;
import com.example.vv.frameWork.entity.LoginEntity;
import com.example.vv.frameWork.entity.RegisterEntity;
import com.example.vv.frameWork.mvp.MvpActivity;
import com.example.vv.frameWork.until.InputTextHelper;
import com.example.vv.frameWork.until.SharePUntitl;
import com.example.vv.frameWork.view.CustomeTitleBar;
import com.example.vv.model.login.LoginAct;
import com.example.vv.model.register.base.contract.RegisterContract;
import com.example.vv.model.register.base.presenter.RegisterPresenter;

import butterknife.BindView;
import butterknife.OnClick;

public class RegisterAct extends MvpActivity<RegisterContract.View, RegisterPresenter> implements RegisterContract.View {
    @BindView(R.id.register_tv)
    TextView register_tv;
    @BindView(R.id.phone_et)
    EditText phone_et;
    @BindView(R.id.code_et)
    EditText code_et;
    @BindView(R.id.pwd_et)
    EditText pwd_et;
    @BindView(R.id.re_pwd_et)
    EditText re_pwd_et;
    @BindView(R.id.title_bar)
    CustomeTitleBar title_bar;
    @BindView(R.id.send_code_tv)
    TextView send_code_tv;
    @BindView(R.id.pwd_eye_iv)
    ImageView pwd_eye_iv;
    @BindView(R.id.re_eye_iv)
    ImageView re_eye_iv;


    @Override
    public Context getMContext() {
        return this;
    }

    @Override
    public int initLayout() {
        return R.layout.act_register;
    }

    @Override
    public RegisterPresenter initPresenter() {
        return new RegisterPresenter();
    }

    @Override
    public void initView() {

    }

    @Override
    public void initData() {
        InputTextHelper.with(this)
                .setMain(register_tv)
                .addView(phone_et)
                .addView(code_et)
                .addView(pwd_et)
                .addView(re_pwd_et)
                .setAlpha(true)
                .setListener(new InputTextHelper.OnInputTextListener() {
                    @Override
                    public boolean onInputChange(InputTextHelper helper) {
                        return presenter.isFormt();
                    }
                }).build();

    }

    @Override
    public void doBusiness() {

    }

    @Override
    public View titleVIew() {
        return null;
    }

    @OnClick({R.id.register_tv})
    public void onClick(View view){
        switch (view.getId()){
            case R.id.register_tv:
                presenter.register();

                break;
        }

    }


    @Override
    public String getPhone() {
        return phone_et.getText().toString();
    }

    @Override
    public String getCaptcha() {
        return code_et.getText().toString();
    }

    @Override
    public String getPassword() {
        return pwd_et.getText().toString();
    }

    @Override
    public String getRepassWord() {
        return re_pwd_et.getText().toString();
    }

    @Override
    public void setReqisterEntity(RegisterEntity reqisterEntity) {
        Integer integer = Integer.valueOf(reqisterEntity.getCode());
        if (integer == 10001) {
            Intent intent = new Intent(RegisterAct.this, LoginAct.class);
            intent.putExtra("phone",phone_et.getText());
            startActivityForResult(intent,99);
            Toast.makeText(this, reqisterEntity.getMessage(), Toast.LENGTH_SHORT).show();
        } else {
            Toast.makeText(this, reqisterEntity.getMessage(), Toast.LENGTH_SHORT).show();

        }
    }
}
